package com.hanthink.web.controller.pc;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.system.domain.pc.EmTaskItem;
import com.hanthink.system.domain.repair.TaskFile;
import com.hanthink.system.service.pc.IEmTaskItemService;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.common.core.page.TableDataInfo;

/**
 * 任务项Controller
 * 
 * @author hanthink
 * @date 2021-01-22
 */
@RestController
@RequestMapping("/equipment/item")
public class EmTaskItemController extends BaseController {
	@Autowired
	private IEmTaskItemService emTaskItemService;

	/**
	 * 查询任务项列表
	 */
	@PreAuthorize("@ss.hasPermi('equipment:item:list')")
	@GetMapping("/list")
	public TableDataInfo list(EmTaskItem emTaskItem) {
		startPage();
		List<EmTaskItem> list = emTaskItemService.selectEmTaskItemList(emTaskItem);
		return getDataTable(list);
	}

	/**
	 * 导出任务项列表
	 */
	@Log(title = "任务项", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(EmTaskItem emTaskItem) {
		List<EmTaskItem> list = emTaskItemService.selectEmTaskItemList(emTaskItem);
		ExcelUtil<EmTaskItem> util = new ExcelUtil<EmTaskItem>(EmTaskItem.class);
		return util.exportExcel(list, "item");
	}

	/**
	 * 获取任务项详细信息
	 */
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(emTaskItemService.selectEmTaskItemById(id));
	}

	/**
	 * 新增任务项
	 */
	@PreAuthorize("@ss.hasPermi('equipment:item:add')")
	@Log(title = "任务项", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody EmTaskItem emTaskItem) {
		return toAjax(emTaskItemService.insertEmTaskItem(emTaskItem));
	}

	/**
	 * 修改任务项
	 */
	@PreAuthorize("@ss.hasPermi('equipment:item:edit')")
	@Log(title = "任务项", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody EmTaskItem emTaskItem) {
		return toAjax(emTaskItemService.updateEmTaskItem(emTaskItem));
	}

	/**
	 * 删除任务项
	 */
	@PreAuthorize("@ss.hasPermi('equipment:item:remove')")
	@Log(title = "任务项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(emTaskItemService.deleteEmTaskItemByIds(ids));
	}

	/**
	 * 查看举证信息
	 */
	@PreAuthorize("@ss.hasPermi('equipment:item:quote')")
	@GetMapping("/quote")
	public AjaxResult selectQuote(TaskFile taskFile) {
		return AjaxResult.success(emTaskItemService.selectEmTaskItemFileByTask(taskFile));
	}
}
